<?php

namespace app\api\controller\v1\store\base;

use app\admin\model\DataUser;
use app\api\controller\Api;


class Info extends Api
{

    /**
     * 获取用户信息
     * @return void
     */
    public function get(){
        $list = $this->getModel()->findOrEmpty();
        if($list->isEmpty())$this->error('用户不存在');
        $this->success('获取成功',$list);
    }


    /**
     * 修改用户信息
     * @return void
     */
    public function set(){
        $rule = [
            'heading'    => 'require',
            'nickname'    => 'require',
            'realname'    => 'require',
            'sex'    => 'require',
            'address'    => 'require',
            'lat'    => 'require',
            'lng'    => 'require',
        ];
        $message  =   [
            'heading.require' => '头像不为空',
            'nickname.require' => '昵称不为空',
            'realname.require' => '真实姓名不为空',
            'sex.require' => '性别不为空',
            'address.require' => '地址不为空',
            'lat.require' => '纬度不为空',
            'lng.require' => '经度不为空',
        ];
        $this->validate($this->post, $rule,$message);
        $list = $this->getModel()->findOrEmpty();
        if($list->isEmpty())$this->error('用户不存在');
        if($list->save($this->post)){
            $this->success('修改成功',$list);
        }else{
            $this->error('修改失败',$list);
        }

    }


    private function getModel(){
        return DataUser::where(['usertype'=>1,'id'=>$this->user['id']]);
    }


}